<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回一个包含函数参数列表的数组</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.func-get-arg.html">« func_get_arg</a></li>
      <li style="float: right;"><a href="function.func-num-args.html">func_num_args »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.funchand.html">函数处理 函数</a></li>
    <li>返回一个包含函数参数列表的数组</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.func-get-args" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">func_get_args</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">func_get_args</span> &mdash; <span class="dc-title">返回一个包含函数参数列表的数组</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.func-get-args-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>func_get_args</strong></span>(): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   获取函数参数列表的数组。
  </p>
  <p class="para">
   该函数可以配合
   <span class="function"><a href="function.func-get-arg.html" class="function">func_get_arg()</a></span> 和 <span class="function"><a href="function.func-num-args.html" class="function">func_num_args()</a></span>
   一起使用，从而使得用户自定义函数可以接受自定义个数的参数列表。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.func-get-args-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.func-get-args-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个数组，其中每个元素都是目前用户自定义函数的参数列表的相应元素的副本。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.func-get-args-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   在用户自定义函数外调用则会出现错误警告。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.func-get-args-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5085">
    <p><strong>示例 #1 <span class="function"><strong>func_get_args()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$numargs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_num_args</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Number&nbsp;of&nbsp;arguments:&nbsp;</span><span style="color: #0000BB">$numargs</span><span style="color: #DD0000">&nbsp;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$numargs&nbsp;</span><span style="color: #007700">&gt;=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Second&nbsp;argument&nbsp;is:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">func_get_arg</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$arg_list&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$numargs</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Argument&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #DD0000">&nbsp;is:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$arg_list</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Number of arguments: 3 
Second argument is: 2
Argument 0 is: 1
Argument 1 is: 2
Argument 2 is: 3
</pre></div>
    </div>
   </div>
  </p>

  <p class="para">
   <div class="example" id="example-5086">
    <p><strong>示例 #2 byRef 和 byVal 参数的 <span class="function"><strong>func_get_args()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">byVal</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'As&nbsp;passed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">()),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$arg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'baz'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'After&nbsp;change&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">()),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br />function&nbsp;</span><span style="color: #0000BB">byRef</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$arg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'As&nbsp;passed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">()),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$arg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'baz'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'After&nbsp;change&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">()),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$arg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">byVal</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">byRef</span><span style="color: #007700">(</span><span style="color: #0000BB">$arg</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen"><br />
As passed     : array (<br />
  0 =&gt; &#039;bar&#039;,<br />
)<br />
After change  : array (<br />
  0 =&gt; &#039;baz&#039;,<br />
)<br />
As passed     : array (<br />
  0 =&gt; &#039;bar&#039;,<br />
)<br />
After change  : array (<br />
  0 =&gt; &#039;baz&#039;,<br />
)<br />
    </div>
   </div>
  </p>

 </div>


 <div class="refsect1 notes" id="refsect1-function.func-get-args-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">As of PHP 8.0.0, the func_*() family of
functions is intended to be mostly transparent with regard to named arguments,
by treating the arguments as if they were all passed positionally,
and missing arguments are replaced with their defaults.
This function ignores the collection of unknown named variadic arguments.
Unknown named arguments which are collected can only be accessed through the variadic parameter.</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">如果参数以引用方式传递，函数对该参数的任何改变将在函数返回后保留。As of PHP 7
the current values will also be returned if the arguments are passed by value.</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    该函数仅仅是返回传递参数的一个副本，并且不包含没有传入的默认参数。
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.func-get-args-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="functions.arguments.html#functions.variable-arg-list" class="link"><code class="literal">...</code> 语法</a></li>
    <li class="member"><span class="function"><a href="function.func-get-arg.html" class="function">func_get_arg()</a></span></li>
    <li class="member"><span class="function"><a href="function.func-num-args.html" class="function">func_num_args()</a></span></li>
    <li class="member"><span class="methodname"><a href="reflectionfunctionabstract.getparameters.html" class="methodname">ReflectionFunctionAbstract::getParameters()</a></span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>